<?php
// oci_connect ( 'user' , 'pass' , "localhost:1521/xe)" );

$this->load->view('header');

if (strlen($this->session->flashdata('Error')) > 0) {
    echo '<div class="alert alert-danger alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Error') . '</div>';
    $this->session->unset_userdata('Error');
} elseif (strlen($this->session->flashdata('Success')) > 0) {
    echo '<div class="alert alert-success alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Success') . '</div>';
    $this->session->unset_userdata('Success');
}
?>

<div id="loader" class="container">
	<form method=post id="access" action="#" enctype="multipart/form-data" class="form-horizontal" role="form">
    <div class="col-md-offset-1">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Search Contract</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-md-6">
						<div class="form-group">
							<label class="col-md-4"><p class="text-left">Contract ID</p></label>
							<div class="col-md-7"><input type="text" class="form-control input-sm" id="search_by_id" name="search_by_id"></div>
						</div>
						<div class="form-group">
							<label class="col-md-4"><p class="text-left">Contract No</p></label>
							<div class="col-md-7"><input type="text" class="form-control input-sm" id="search_by_no" name="search_by_no"></div>
						</div>
					</div>
					<div class="col-sm-6 col-md-5">
						<div class="form-group">
							<label class="col-md-5"><p class="text-left">Contract Title</p></label>
							<div class="col-md-7"><input type="text" class="form-control input-sm" id="search_by_title" name="search_by_title"></div>
						</div>
						<div class="form-group">
							<label class="col-md-5"><p class="text-left">Vendor Name</p></label>
							<div class="col-md-7"><input type="text" class="form-control input-sm" id="search_by_vendor" name="search_by_vendor"></div>
						</div>
						<div class="form-group">
							<div class="col-md-5"><label for="button" class="control-label">&nbsp;</label></div>
							<div class="col-md-3">
								<button type="button" class="btn btn-primary btn-sm" onclick="search_data();">
								<!--span class="glyphicon glyphicon-search"></span--> Search</button>
							</div>
							<div class="col-md-3">
								<button type="reset" class="btn btn-default btn-sm">
								<!--span class="glyphicon glyphicon-refresh"></span--> Clear</button>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="panel-body well">
				<div class="col-md-6">
					<div class="form-group">
						<div class="col-md-4">
							<button type="button" class="btn btn-success btn-sm" onclick="add_data();">
							<!--span class="glyphicon glyphicon-plus"></span--> Add Contract</button>
						</div>
					</div>
				</div>
				<div id="tablecontent" class="col-md-12">						
					<div class="form-group">
						<div class="table-responsive">
							<table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
								<thead>
									<tr>
										<th class="tblhead" style="width:5%;text-align:center;">No</th>
										<th class="tblhead" style="width:15%;text-align:center;">Contract ID</th>
										<th class="tblhead" style="width:15%;text-align:center;">Contract No</th>
										<th class="tblhead" style="width:15%;text-align:center;">Contract Title</th>
										<th class="tblhead" style="width:15%;text-align:center;">Period Date</th>
										<th class="tblhead" style="width:10%;text-align:center;">File Name</th>
										<th class="tblhead" style="width:15%;text-align:center;">Vendor Name</th>
										<th class="tblhead" style="width:10%;text-align:center;">Action</th>
									</tr>
								</thead>
								<tbody>
									<?php
									if (empty($list_data)) {
										?>
										<tr><td colspan="9" style="text-align:center">No Data Available</td></tr>
										<?php
									} else {
										foreach ($list_data as $row) {
											?>
											<tr>
												<?php
												$doc_id		= $row["DOC_ID"];
												$doc_induk	= $row["DOC_INDUK"];
												
												$doc_no		= $row["DOC_CONTRACT_NO"];
												$doc_title 	= $row["DOC_TITLE"];
												$start_date	= $row["DOC_SDATE"];
												$end_date 	= $row["DOC_EDATE"];
												$doc_file	= $row["DOC_FILE"];
												$vendor		= $row["VENDOR_NAME"];												
												?>

												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;"><?php echo $row["RECNUM"]; ?>.</td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $doc_id; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $doc_no; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;word-warp:break-word;"><?php echo $doc_title; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;word-warp:break-word;">
												<?php echo $start_date.' <b>s/d</b> '.$end_date; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $doc_file; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;word-warp:break-word;"><?php echo $vendor; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;">
													<a class="btn btn-sm btn-info" href="#" onclick="edit_data('<?php echo $doc_id; ?>','<?php echo $doc_induk; ?>','Revise');">
														<!--span class="glyphicon glyphicon-cog"></span--> Revise</a>
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data('<?php echo $doc_id; ?>','<?php echo $doc_induk; ?>','Edit');">
														<!--span class="glyphicon glyphicon-edit"></span--> Edit</a>
													<a class="btn btn-sm btn-danger" href="#" onclick="delete_data('<?php echo $doc_id; ?>','<?php echo $doc_induk; ?>');">
														<!--span class="glyphicon glyphicon-remove"></span--> Delete</a>
												</td>
											</tr>
											<?php
										}
									}
									?>
								</tbody>
							</table>
						</div>
					</div>
					<div class="form-group">
						<div id="mypaging">
							<?php
							echo $paging;
							echo $jump_page;
							echo $ipp;
							?>
						</div>								
					</div>
				</div>						
			</div>
		</div>
	</div>
</div>

<?php $this->load->view('footer'); ?>

<script type="text/javascript">
    function search_data() {
        $.post("<?= site_url() ?>setup/search_contract", {
            search_by_id: $('#search_by_id').val(),
			search_by_no: $('#search_by_no').val(),
			search_by_title: $('#search_by_title').val(),
			search_by_vendor: $('#search_by_vendor').val()
        },
        function(data) {
            $('#tablecontent').html(data);
        });
    }

    function add_data() {
        $.post("<?= site_url() ?>setup/add_contract", function(data) {
            $('#loader').html(data);
        });
    }
	
	function edit_data(doc_id,doc_induk,status_id) {		
        $.post("<?= site_url() ?>setup/edit_contract", {doc_id: doc_id, doc_induk: doc_induk, status_id: status_id}, function(data) {
            $('#loader').html(data);
        });
    }	
	
	function delete_data(doc_id, doc_title){		
		if (confirm("Apakah Anda Yakin Ingin Delete Contract '"+ doc_title +"' ?")){
			$.post("<?= site_url() ?>setup/delete_data_contract", {doc_id: doc_id}, function(data) {
				window.location = '<?php echo base_url();?>setup/contract';
				// $('#loader').html(data);
			});
		}
	}
</script>
